﻿#region using
using System;
using System.Drawing;
using RRRSRoguelike.Enums;
using RRRSRoguelike.Helpers;
using RRRSRoguelike.Helpers.Visualizer;
using RRRSRoguelike.Managers;
#endregion

namespace RRRSRoguelike.Screens
{
	/// <summary>
	/// Manages the UI to handle quiting the game.
	/// </summary>
	class OptionsScreen : Screen
	{
		
		#region variables
		MenuPanel MainPanel;
		bool quit;
		bool showMenu = true;
		Menu menu;
		#endregion
		
		#region constructor
		public OptionsScreen()
		{
			PanelList.Add(new MenuPanel(new Point(4, 3),
				  Visualizer.GetScreenWidth() - 9, Visualizer.GetScreenHeight() - 6));

			MainPanel = (MenuPanel)PanelList[0];
			
			menu = MainPanel.Menu;
		}
		#endregion
		
		#region methods
		/// <summary>
		/// Returning true will quit the current game.
		/// </summary>
		/// <returns></returns>
		public bool ShowYesNo()
		{

			quit = false;
			
			Show();

			return quit;
		}

		public override void Show()
		{
			Clear();
			
			//The following are necessary for the menu.
			SetupMenu(menu);
			MainPanel.Draw();
			MainPanel.DrawMenu();
			while(showMenu)
				MainPanel.HandleInput();
			
			ApplicationManager.Instance.SoundManager.PlaySound(SoundList.Pluck.ToString());
		}
		
		void SetupMenu(Menu menu)
		{
			//HACK: should be a Properties.String
			menu.Add(new MenuItem("Edit profile", SelectProfile));
			menu.Add(new MenuItem("Select RuleSet", SelectRuleSet));
			menu.Add(new MenuItem(Properties.Strings.SelectLanguage, SelectLanguage));
			menu.Add(new MenuItem("Clear high scores", SelectClearHighScores));
			menu.Add(new MenuItem("Backup and reset custom content", SelectBackupCustomContent));
			menu.Add(new MenuItem("Exit", SelectExit));
		}
		
		#endregion
		
		#region delegates

		//Event method
		void SelectProfile(object sender, EventArgs e)
		{
			Properties.Settings.Default.Profile = "-1";
			ApplicationManager.Instance.ScreenStack.Push(new OptionsScreen());
			ApplicationManager.Instance.ScreenStack.Push(new ProfileScreen());
			quit = true;
			showMenu = false;
		}
		
		
		
		//Event method
		void SelectRuleSet(object sender, EventArgs e)
		{
			ApplicationManager.Instance.ScreenStack.Push(new RuleSetScreen());
			quit = true;
			showMenu = false;
		}
		
		//Event method
		void SelectLanguage(object sender, EventArgs e)
		{
			ApplicationManager.Instance.ScreenStack.Push(new LanguageScreen());
			quit = true;
			showMenu = false;
		}
		
	    //Event method
		void SelectBackupCustomContent(object sender, EventArgs e)
		{
			
			Language.BackupContentFolder();	
			Language.PrepareContentFolder();
			//HACK: No check to confirm it is actually done.
			var textScreen = new TextScreen("Done!");
			textScreen.Show();
		}
		
			    //Event method
		void SelectClearHighScores(object sender, EventArgs e)
		{
			
			ApplicationManager.Instance.Profile.ClearHighScores();
			//HACK: No check to confirm it is actually done.
			var textScreen = new TextScreen("Done!");
			textScreen.Show();
		}
		
		void SelectExit(object sender, EventArgs e)
		{
			quit = true;
			showMenu=false;
			ApplicationManager.Instance.ScreenStack.Push(new MenuScreen());
		}
		
		#endregion
		
	}
}
